package org.yihang.annotation.easyui;

public enum FormatterType {
    NONE {
        @Override
        public String funcBody(String value) {
            return "";
        }
    }, DATE {
        @Override // value example: return 'yyyy-MM-dd' -> return d.getFullYear()+'-'+(d.getMonth()+1)+'-'+d.getDate();
        public String funcBody(String value) {
            String body = "var d = new Date(value);" +
                    "return '" + value + "';";
            return body.replaceAll("yyyy", "'+d.getFullYear()+'")
                    .replaceAll("MM", "'+((d.getMonth()+1)<10?('0'+(d.getMonth()+1)):(d.getMonth()+1))+'")
                    .replaceAll("dd", "'+(d.getDate()<10?('0'+d.getDate()):d.getDate())+'")
                    .replaceAll("HH", "'+(d.getHours()<10?('0'+d.getHours()):d.getHours())+'")
                    .replaceAll("mm", "'+(d.getMinutes()<10?('0'+d.getMinutes()):d.getMinutes())+'")
                    .replaceAll("ss", "'+(d.getSeconds()<10?('0'+d.getSeconds()):d.getSeconds())+'");
        }
    }, SOURCE {
        @Override // 这里的value是Source名
        public String funcBody(String value) {
            return "return " + value + "[value];";
        }
    };

    public abstract String funcBody(String value);
}
